package javango.contrib.i18n;

import java.util.IllegalFormatException;
import java.util.Locale;
import java.util.Map;

public class ThreadLocalProvider extends AbstractI18NProvider implements I18NProvider {
	
	private static ThreadLocal<Locale> threadLocalLocale = new ThreadLocal<Locale>() {

		@Override
		public Locale get() {
			return super.get();
		}

		public void set(Locale arg0) {
			super.set(arg0);
		}
	};

	/**
	 * Sets the ThreadLocal Locale.
	 * 
	 * @param provider
	 */
	public static void setCurrentLocale(Locale locale) {
		threadLocalLocale.set(locale);
	}

	@Override
	public Locale getLocale() {
		Locale locale = threadLocalLocale.get(); 
		if ( locale == null) {
			throw new NullPointerException(
					"Locale not set,  please call ThreadLocalProvider.setCurrentLocale");
		}
		return locale;
	}
}
